<?php

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Request;

class ContactController extends Controller
{
   public function getContactList(){

       try{
           $results = DB::table('contact')->paginate(5);
//            dd($results);

           return view('Admin.contactlist',['results'=> $results]);

       }catch (Exception $e){

           $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
           return json_encode(['msg'=>0,'data' => $info]);
           exit;
       }
   }

    public function deleteContact(){

        try{
            $data = Request::only('contact_id');
            var_dump($data);
            $results = DB::table('contact')->where('contact_id','=',$data['contact_id'])->delete();

            if($results){

                return redirect('/admin/getContactList');
            }

        }catch (Exception $e){

            $info =  $e->getMessage().'failed line:'.$e->getLine().'failed string:'.$e->getTraceAsString();
            return json_encode(['msg'=>0,'data' => $info]);
            exit;
        }

    }
}
